#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using std::vector;
using namespace std;

// 方法1：暴力破解
class Solution {
public:
    int removeElement(vector<int>& nums, int val) {
        size_t size = nums.size();

        for(int i = 0;i < size;++ i)
        {
            if(nums[i] != val) continue;

            for(int j = i + 1;j < size;++ j)
            {
                nums[j - 1] = nums[j];
            }
            -- size;
            -- i;
        }
        return size;
    }
};

// 方法2：快慢指针
class Solution {
public:
    int removeElement(vector<int>& nums, int val) {
        int slow = 0; 
        int fast = 0;
        for(size_t i = 0;i < nums.size(); ++ i)
        {
            if(nums[fast] != val)
            {
                nums[slow] = nums[fast];
                ++ slow; ++ fast;
            }
            else
            {
                ++ fast;
            }
        }
        return slow;
    }
};


int main(int argc, char const *argv[])
{
    vector<int> v = {3,2,2,3};
    Solution s;
    int size = s.removeElement(v,3);
    cout << size << endl;
    getchar();
    return 0;
}
